package com.key.oa.common;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Json {

	public static List<Map<String,String>> parse( String result ) {
		
		int start = result.indexOf("[", 0);
		if( start == -1 ) {
			return null;
		}
		
		List<Map<String,String>> list = new LinkedList<Map<String,String>>();
		
		int end = start;
		while( true ) {
			
			Map<String,String> map = new HashMap<String,String>();
			
			start = result.indexOf("{", end+1);
			if( start == -1 ) {
				return list;
			}
			end = result.indexOf("}", start+1);
			String str = result.substring(start+1,end); 
			String[] keyvalue = str.split(",");
			if( keyvalue == null ) {
				return list;
			}
			
			for( String kv : keyvalue ) {
				
				int skvStart = kv.indexOf("\"");
				int skvEnd = kv.indexOf("\"",skvStart+1);
				String str1 = kv.substring(skvStart+1,skvEnd);
				skvStart = kv.indexOf("\"",skvEnd+1);
				skvEnd = kv.indexOf("\"", skvStart+1);
				String str2 = kv.substring(skvStart+1,skvEnd);
				map.put(str1, str2);
			}
			
			list.add(map);
			
		}
	}
	
}
